package com.open.party.cloud.view.home.jiCengDangJian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.open.party.cloud.R;
import com.open.party.cloud.model.PartyDevBean;
import com.sinothk.android.utils.XUtils;
import com.sinothk.view.image.rounded.RoundedImageView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import com.sinothk.android.utils.inters.OnSuperListener;

public class DyfzDevStepListAdapter extends RecyclerView.Adapter<DyfzDevStepListAdapter.ViewHolder> {

    // 展示数据
    private ArrayList<PartyDevBean> mData;
    private Context mContext;
    private OnSuperListener<PartyDevBean> onSuperListener;

    public DyfzDevStepListAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

    public void setOnSuperListener(OnSuperListener<PartyDevBean> onSuperListener) {
        this.onSuperListener = onSuperListener;
    }

    public void setData(List<PartyDevBean> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<PartyDevBean> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public DyfzDevStepListAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.dyfz_dev_step_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(DyfzDevStepListAdapter.ViewHolder holder, final int position) {
        // 绑定数据
        final PartyDevBean itemData = mData.get(position);

        holder.titleTv.setText(XUtils.string().getNotNullValue(itemData.getProgressStage()));
        holder.contentTv.setText(XUtils.string().getNotNullValue(itemData.getProgressDesc()));

        String upType = position - 1 >= 0 ? mData.get(position - 1).getProgressStage() : "";
        String type = mData.get(position).getProgressStage();

        if (!type.equals(upType)) {
            holder.typeView.setVisibility(View.VISIBLE);
        } else {
            holder.typeView.setVisibility(View.GONE);
        }

        if (position == mData.size() - 1) {
            holder.bottomLineTv.setVisibility(View.VISIBLE);
        } else {
            holder.bottomLineTv.setVisibility(View.GONE);
        }

        if (onSuperListener != null) {
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onSuperListener.onClick(position, itemData, "");
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout rootView;
        LinearLayout typeView;

        TextView titleTv, contentTv, bottomLineTv, allTimeTv, thisYearNumTv, lastYearNumTv, ageTv;

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            typeView = itemView.findViewById(R.id.typeView);

            titleTv = itemView.findViewById(R.id.titleTv);
            contentTv = itemView.findViewById(R.id.contentTv);

            bottomLineTv = itemView.findViewById(R.id.bottomLineTv);

//            allTimeTv = itemView.findViewById(R.id.allTimeTv);
//            thisYearNumTv = itemView.findViewById(R.id.thisYearNumTv);
//            lastYearNumTv = itemView.findViewById(R.id.lastYearNumTv);
//
//            phoneTv = itemView.findViewById(R.id.phoneTv);
//            emailTv = itemView.findViewById(R.id.emailTv);
//
//            imageView = itemView.findViewById(R.id.imageView);
        }
    }
}